package com.tarena.lbs.business.rpc;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.business.api.BusinessApi;
import com.tarena.lbs.business.api.pojo.BusinessDto;
import com.tarena.lbs.business.api.pojo.StoreDto;
import com.tarena.lbs.business.pojo.vo.BusinessStoreVO;
import com.tarena.lbs.business.pojo.vo.BusinessVO;
import com.tarena.lbs.business.pojo.vo.StoreVO;
import com.tarena.lbs.business.servcie.BusinessService;
import com.tarena.lbs.business.servcie.StoreService;
import com.tarena.lbs.business.servcie.impl.BusinessServiceImpl;
import com.tarena.lbs.business.servcie.impl.StoreServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

@DubboService
@Slf4j
public class BusinessApiImpl implements BusinessApi {

    @Resource
    private BusinessServiceImpl businessService;

    @Resource
    private StoreServiceImpl storeService;

    @Override
    public BusinessDto getBusinessById(Integer businessId) {
        BusinessDto businessDto = new BusinessDto();
        BusinessVO businessVO = null;
        try {
            businessVO = businessService.selectById(businessId);
        }catch(BusinessException e){
            log.error("查询商家详情异常:{}",e.getMessage());
            return businessDto;
        }
        BeanUtils.copyProperties(businessVO,businessDto);
        return businessDto;
    }

    @Override
    public StoreDto getStoreById(Integer storeId) {
        StoreDto storeDto = new StoreDto();
        StoreVO storeVO = storeService.getStoreById(storeId);
        if (storeVO == null){
            return storeDto;
        }
        storeDto.setId(storeVO.getId());
        storeDto.setStoreName(storeVO.getStoreName());
        return storeDto;
    }

}
